import { workspace, WorkspaceConfiguration } from 'vscode';
import { ConfigConst, GlobalConst } from '../constants';

/**
 * 插件配置
 *
 * @author chitanda
 * @date 2022-12-12 21:12:42
 * @export
 * @class PluginConfig
 */
export class PluginConfig {
  /**
   * vscode 当前插件配置参数
   *
   * @author chitanda
   * @date 2022-12-12 21:12:18
   * @protected
   * @type {WorkspaceConfiguration}
   */
  protected pluginConfig: WorkspaceConfiguration = workspace.getConfiguration(
    GlobalConst.PLUGIN_CODE,
  );

  get cloudAddress(): string {
    return this.getConfig<string>(ConfigConst.CLOUD_ADDRESS) || '';
  }

  get mqttAddress(): string {
    return this.getConfig<string>(ConfigConst.MQTT_ADDRESS) || '';
  }

  get systemId(): string {
    return this.getConfig<string>(ConfigConst.SYSTEM_ID) || '';
  }

  /**
   * 获取 vscode 配置
   *
   * @author chitanda
   * @date 2022-12-12 21:12:05
   * @template T
   * @param {string} key
   * @return {*}  {(T | undefined)}
   */
  getConfig<T = unknown>(key: string): T | undefined {
    return this.pluginConfig.get<T>(key);
  }
}
